// pages/recharge-list/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CurrentPage:1,
    recordList:[],
    totalPages: 1,
    direction: 1,//1充值2消费
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.cashRecordList(options.direction);
    this.data.direction = options.direction;
    if(options.direction == 1){
      wx.setNavigationBarTitle({
        title: '充值记录',
      })
    }else{
      wx.setNavigationBarTitle({
        title: '消费记录',
      })
    }

  },
  //获取充值列表
  cashRecordList:function(direction){
    var that = this
    wx.request({
      url: app.globalData.host + '/api/ship/GetCashRecordList?uid=' + app.globalData.userInfo.Uid + '&storeid='+ app.globalData.storeId + '&direction='+ direction +'&page=' + that.data.CurrentPage,
      success: function(res) {
       if(res.data.Code == 0){
         var recordList = res.data.Data.Items;
         if (that.data.CurrentPage != 1) {
           var preGoods = that.data.recordList
           recordList = preGoods.concat(recordList);
         }
         that.setData({
           recordList: recordList,
           totalPages: res.data.Data.TotalPages
         })
       }
      },
    })
  },
  //加载更多
  loadMore: function (e) {
    var that = this;
    if (that.data.totalPages == 1 || that.data.CurrentPage >= that.data.totalPages) return;
    var currPage = that.data.CurrentPage;
    that.setData({
      CurrentPage: currPage + 1
    })
    that.cashRecordList(this.data.direction);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.loadMore();
  }
})